﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RssFeederASPClient.Controllers
{
    public class RssController : Controller
    {
        //
        // GET: /Rss/

        public ActionResult Index()
        {
            Rss.RssFeedServiceClient rss = new Rss.RssFeedServiceClient();
            Rss.RssFeed[] rsslist = rss.ListRssFeed((Rss.Session)Session["session"]);
            ViewBag.RssFeed = rsslist;
            return View();
        }

        
        public ActionResult ListRss(int id, int id_item = 0)
        {
            Rss.RssFeedServiceClient rss = new Rss.RssFeedServiceClient();
            if (id_item != 0)
            {
                Rss.RssFeedItem feedItem = new Rss.RssFeedItem();
                feedItem.id = id_item;
                rss.ReadSate((Rss.Session)Session["session"], feedItem, true);
            }
            
            Rss.RssFeed feed = new Rss.RssFeed();
            feed.id = id;
            
            ViewBag.RssFeed = rss.ListRssFeedItem((Rss.Session)Session["session"], feed);
            ViewBag.id = id;
            
            return View();
        }

        public ActionResult AddRss(string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;
            return View();
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult AddRss(RssFeederASPClient.Models.RssModels.NewRssModel model, string returnUrl)
        {
            Rss.RssFeedServiceClient rss = new Rss.RssFeedServiceClient();
            Rss.RssFeed rssfeed = new Rss.RssFeed();
            rssfeed.url = model.Lien;
            rss.Subscribe((Rss.Session)Session["session"], rssfeed);
            return Redirect("/Rss");
        }

        [HttpPost]
        public ActionResult ListRss(string url)
        {
            
            return View();
        }

    }
}
